package com.sawyerqiu.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author : SawyerQiu
 * @date : 2024/7/30 11:04
 */
public class DateUtil {

    public static long ZONE_OFFSET = TimeZone.getDefault().getOffset(System.currentTimeMillis());

    public static long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;

    public static boolean isSameDay(Date date1, Date date2) {
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        return fmt.format(date1).equals(fmt.format(date2));
    }

    public static long getMorningTimeMillis(){
        return toDay(System.currentTimeMillis()) * MILLIS_PER_DAY - ZONE_OFFSET;
    }

    public static int toDay(long timeMillis) {
        return (int) ((timeMillis + ZONE_OFFSET) / MILLIS_PER_DAY);
    }
}
